package com.ruoyi.api.controller;

import com.ruoyi.api.service.CollectApiService;
import com.ruoyi.api.vo.ApiDemo;
import com.ruoyi.common.core.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 收藏功能
 */
@RestController
@RequestMapping("/api/sys/collectapi")
public class CollectApiController {

    @Autowired
    private CollectApiService collectApiService;

    /**
     * 收藏添加
     * @param apiDemo
     * @return
     */
    @PostMapping("insertCollect")
    public AjaxResult insertCollect(@RequestBody ApiDemo apiDemo){
        boolean a = collectApiService.insertCollect(apiDemo);
        if(a){
            return AjaxResult.success("上传成功");
        }else {
            return AjaxResult.error("上传失败");
        }
    }

    /**
     * 收藏查询
     * @param id
     * @return
     */
    @PostMapping("selectCollect")
    public AjaxResult selectCollect(@RequestBody String id){
        List<ApiDemo> list = collectApiService.selectCollect(id);
        return AjaxResult.success(list);
    }

    /**
     * 收藏删除
     * @param id
     * @return
     */
    @DeleteMapping("delectCollect")
    public AjaxResult delectCollect(@RequestBody String id){
        collectApiService.delectCollect(id);
        return AjaxResult.success();
    }

    /**
     * 收藏修改
     * @param apiDemo
     * @return
     */
    @PutMapping("updateCollect")
    public AjaxResult updateCollect(@RequestBody ApiDemo apiDemo){
        collectApiService.updateCollect(apiDemo);
        return AjaxResult.success();
    }
}
